﻿//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Linq;
//using System.Runtime.Serialization;
//using System.ServiceModel.Channels;
//using System.Text;
//using System.Threading.Tasks;
//using System.Xml;
//using System.Xml.Serialization;
//using Sripirom.ATS.Core.Configuration;
//using Sripirom.ATS.Core.Helpers;

//namespace Sripirom.ATS.Core.Messaging
//{
//    //[DataContract]
//    //public class ServiceHeader
//    //{
//    //    [DataMember]
//    //    public string EmployeeID { get; set; }

//    //    [DataMember]
//    //    public string WindowsLogonID { get; set; }

//    //    [DataMember]
//    //    public string KerberosID { get; set; }

//    //    [DataMember]
//    //    public string SiteminderToken { get; set; }
//    //}                                                  

//    //public class ServiceMessageHeader : MessageHeader
//    //{
//    //    private const string CUSTOM_HEADER_NAME = "atsHeader";
//    //    private const string CUSTOM_HEADER_NAMESPACE = "http://schemas.microsoft.com/42";
//    //    //private const String HeaderName = "atsHeader";
//    //    //private const String HeaderNamespace = "http://schemas.microsoft.com/42";
//    //    //private ServiceHeader _customData;

//    //    //public ServiceHeader CustomData
//    //    //{
//    //    //    get
//    //    //    {
//    //    //        return _customData;
//    //    //    }
//    //    //}
//    //    [DataMember]
//    //    public string EmployeeID { get; set; }

//    //    [DataMember]
//    //    public string WindowsLogonID { get; set; }

//    //    [DataMember]
//    //    public string KerberosID { get; set; }

//    //    [DataMember]
//    //    public string SiteminderToken { get; set; }

//    //    public ServiceMessageHeader()
//    //    {
//    //    }

//    //    //public ServiceMessageHeader(ServiceHeader customData)
//    //    //{
//    //    //    _customData = customData;
//    //    //}

//    //    public override string Name
//    //    {
//    //        get { return (CUSTOM_HEADER_NAME); }
//    //    }

//    //    public override string Namespace
//    //    {
//    //        get { return (CUSTOM_HEADER_NAMESPACE); }
//    //    }

//    //    protected override void OnWriteHeaderContents(
//    //        System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion)
//    //    {
//    //        XmlSerializer serializer = new XmlSerializer(typeof(ServiceMessageHeader));
//    //        StringWriter textWriter = new StringWriter();
//    //        serializer.Serialize(textWriter, this);    
//    //        textWriter.Close();

//    //        string text = textWriter.ToString();

//    //        writer.WriteElementString(CUSTOM_HEADER_NAME, "Key", text.Trim());
//    //    }

//    //    public static ServiceHeader ReadHeader(Message request)
//    //    {
//    //        Int32 headerPosition = request.Headers.FindHeader(CUSTOM_HEADER_NAME, CUSTOM_HEADER_NAMESPACE);
//    //        if (headerPosition == -1)
//    //            return null;

//    //        MessageHeaderInfo headerInfo = request.Headers[headerPosition];

//    //        XmlNode[] content = request.Headers.GetHeader<XmlNode[]>(headerPosition);

//    //        string text = content[0].InnerText;

//    //        XmlSerializer deserializer = new XmlSerializer(typeof(ServiceHeader));
//    //        TextReader textReader = new StringReader(text);
//    //        ServiceHeader customData = (ServiceHeader)deserializer.Deserialize(textReader);
//    //        //(ServiceHeader)deserializer.Deserialize(new StringReader("<ServiceHeader>" + request.Headers.GetHeader<XmlNode[]>(0)[1].InnerXml + "</ServiceHeader>"));
//    //        textReader.Close();

//    //        return customData;
//    //    }
//    //}

//    [DataContract(Name = "ServiceMessageHeader", Namespace = "http://schemas.microsoft.com/42")]
//    public class ServiceMessageHeader : MessageHeader
//    {
//        private const String CUSTOM_HEADER_NAME = "ServiceMessageHeader";
//        private const String CUSTOM_HEADER_NAMESPACE = "http://schemas.microsoft.com/42";

//        private String _transactionId = "";
//        private String _username = "";
//        private String _password = "";
//        private String _serviceName = "";
//        private String _channelId = "";
//        private String _transactionDate = "";
//        private String _transactionTime = "";
//        //public ServiceMessageHeader(String transactionId)
//        //{
//        //    _transactionId = transactionId;
//        //}
//        [DataMember(Name = "TransactionId")]
//        public String TransactionId { get { return _transactionId; } set { _transactionId = value; } }
//        [DataMember(Name = "Username")]
//        public String Username { get { return _username; } set { _username = value; } }
//        [DataMember(Name = "Password")]
//        public String Password { get { return _password; } set { _password = value; } }
//        [DataMember(Name = "ServiceName")]
//        public String ServiceName { get { return _serviceName; } set { _serviceName = value; } }
//        [DataMember(Name = "ChannelId")]
//        public String ChannelId { get { return _channelId; } set { _channelId = value; } }
//        [DataMember(Name = "TransactionDate")]
//        public String TransactionDate { get { return _transactionDate; } set { _transactionDate = value; } }
//        [DataMember(Name = "TransactionTime")]
//        public String TransactionTime { get { return _transactionTime; } set { _transactionTime = value; } }



//        public override string Name
//        {
//            get { return CUSTOM_HEADER_NAME; }
//        }

//        public override string Namespace
//        {
//            get { return CUSTOM_HEADER_NAMESPACE; }
//        }


//        protected override void OnWriteHeaderContents(System.Xml.XmlDictionaryWriter writer, MessageVersion messageVersion)
//        {
//            writer.WriteElementString("transactionId", TransactionId.ToString());
//            writer.WriteElementString("username", Username);
//            writer.WriteElementString("password", Password);
//            writer.WriteElementString("serviceName", ServiceName);
//            writer.WriteElementString("channelId", ChannelId);
//            writer.WriteElementString("transactionDate", TransactionDate);
//            writer.WriteElementString("transactionTime", TransactionTime);

//        }

//        public static ServiceMessageHeader ReadHeader(Message request)
//        {
//            // Read the header content (key) using the XmlDictionaryReader
//            Int32 headerPosition = request.Headers.FindHeader(CUSTOM_HEADER_NAME, CUSTOM_HEADER_NAMESPACE);
//            if (headerPosition == -1)
//                return null;

//            MessageHeaderInfo headerInfo = request.Headers[headerPosition];

//           // XmlNode[] content = request.Headers.GetHeader<XmlNode[]>(headerPosition);

//            string text = headerInfo.ToString().Replace("<ServiceMessageHeader xmlns=\"http://schemas.microsoft.com/42\">", "<ServiceMessageHeader>");// content[0].InnerText;

//            XmlSerializer deserializer = new XmlSerializer(typeof(ServiceMessageHeader));
//            TextReader textReader = new StringReader(text);
//            ServiceMessageHeader customData = SerializationHelper.Deserialize<ServiceMessageHeader>(text);// (ServiceMessageHeader)deserializer.Deserialize(textReader);
//            //(ServiceHeader)deserializer.Deserialize(new StringReader("<ServiceHeader>" + request.Headers.GetHeader<XmlNode[]>(0)[1].InnerXml + "</ServiceHeader>"));
//            textReader.Close();

//            return customData;
//        }
//    }
//}
